package de.hwr.sudokuspielehr.ui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import de.hwr.sudokuspielehr.ui.UserInterface;

public class BackToSudokuListener implements ActionListener {

	UserInterface ui;

	public BackToSudokuListener(UserInterface pUi) {
		ui = pUi;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (ui.isInCreatorMode()) {
			ui.setSudokuOpen(false);
			ui.switchTo(UserInterface.PANEL_CREATEMENUPANEL);
			ui.setSudokuOpen(true);
		} else {
			if (!ui.getSolutionDisplayed()) {
				ui.openSudoku(ui.getSudoku(), false, 2);
			} else {
				ui.openSudoku(ui.getSudoku(), false, 1);
			}

			if (e != null) {
				Object o = e.getSource();
				if (o instanceof JButton) {
					((JButton) e.getSource()).setVisible(false);
				}
			}
		}
	}
}
